import api from '../../server/api';

const state = {
    tleft:[],
    tright:[],
    tlist:[],
    tget:[],
    flag:0,
    str:"综合"
    
}

const getters = {}

const actions = {
    // 获取type页左侧数据
    TypeLeftData({ commit }){
        api.loadDataByTypeLeft({
            appPlat:"m",
            pids:"41789"
        }).then(({ data })=>{
            commit("setTleft",data[41789].list);
            // console.log(data[41789].list)
        });
    },
    // 传进去整个对象 
    // TypeRightData({ commit },params={appPlat:'m',pid:"41888"}){
    //     api.loadDataByTypeRight(
    //         params
    //     ).then(( {data} )=>{
    //         commit("setTright",data.categoryNavigation.list);
    //     })
    // }

    // 传pid单个参数
    // 获取type页右侧上端数据
    TypeRightData({ commit },params={pid:"41888",fcid:"10062603"}){
        api.loadDataByTypeRight(
            {
                appPlat:"m",
                pid:params.pid
            }
        ).then(( {data} )=>{
            //console.log(data)
            commit("setTright",data.categoryNavigation.list);
        }),
        api.loadDataByLike({
            page:1,
            sort:"pop",
            cKey:"h5-cube",
            fcid:params.fcid
        })
        .then(( {result} )=>{
            commit("setTlist",result.wall.docs);
            commit("setTget",result);
            // console.log(result.wall.docs)
        })
    },
    //获取 type页右侧上端点击数据
    TypeListData( {commit} ,fcid="10062603"){
        api.loadDataByLike({
            page:1,
            sort:'pop',
            cKey:"16",
            fcid,
            title:"综合"
        })
        .then(( {result} )=>{
            commit("setTlist",result.wall.docs);
            commit("setTget",result);
            // console.log('11111',result)

        })
    },
    // 获取type页下端类目变化数据
    TypeRightListClass({commit},params={fcid:"10062603",sort:"pop"}){
        api.loadDataByLike({
            page:1,
            sort:params.sort,
            cKey:"h5-cube",
            fcid:params.fcid
        })
        .then(( {result} )=>{
            commit("setTlist",result.wall.docs);
            commit("setTget",result);
            // console.log(result.wall.docs)
        })
    },

    changeLeftStyle({commit},params){
        commit("setFlag",params);
    },

    changeListStyle({commit},params){
        commit("setStr",params);
    },

    

    

}

const mutations = {
    setTleft(state,data){
        state.tleft = data
    },
    setTright(state,data){
        state.tright = data

    },
    setTlist(state,data){
        state.tlist = data

    },
    setTget(state,data){
        state.tget = data
    },
    setFlag(state,data){
        state.flag = data
    },
    setStr(state,data){
        state.str = data
    },
    


}

export default {
    state,
    actions,
    mutations,
    getters
}
